package com.base.www.test1;

/**
 * Created by guoqi on 2017/7/28.
 */
public class Test {
    private static UnaryFunction<Object> IDENTITY_FUNCTION = new UnaryFunction<Object>(){
        public Object apply(Object arg){
          return arg;
        }
    };

    public static <T> UnaryFunction<T> identityFunction(){
        return (UnaryFunction<T>) IDENTITY_FUNCTION;
    }

    public static void main(String[] args){
        String[] strings = {"jute", "hemp", "nylon"};
        UnaryFunction<String> sameString = identityFunction();
        for(String s:strings){
            System.out.println(sameString.apply(s));
        }
        Number[] numbers = {1,2.0,3L};
        UnaryFunction<Number> sameNumber = identityFunction();
        for(Number number:numbers){
            System.out.println(sameNumber.apply(number));
        }
    }
}
